<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Qiniu\Auth;

use App\Http\Requests;

class Qiniu extends Controller
{
    // 生成七牛token
    public function token()
    {
        // 用于签名的公钥和私钥
        $accessKey = 'eKFkHkGLqZLbV6ulMWtuGh9AxBEGTvCIf8HQGfKq';
        $secretKey = 'OTxMNFdopWUBdbhvGXKykcEpf-JnOGVlPZJeaO96';
        $bucket = 'lingting';

        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);
        $upToken = $auth->uploadToken($bucket);

        return response(array('code' => 200, 'msg' => '', 'rst' => array('url' => 'http://up.qiniu.com', 'token' => $upToken)));
    }

    public function test()
    {
        // 用于签名的公钥和私钥
        $accessKey = 'eKFkHkGLqZLbV6ulMWtuGh9AxBEGTvCIf8HQGfKq';
        $secretKey = 'OTxMNFdopWUBdbhvGXKykcEpf-JnOGVlPZJeaO96';
        $bucket = 'lingting';

        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);
        $upToken = $auth->uploadToken($bucket);


        return '<form method="post" action="http://up.qiniu.com" enctype="multipart/form-data">
  <input name="token" type="hidden" value="'.$upToken.'">
  <input name="file" type="file" />
  <input type="submit" value="上传"/>
</form>';

    }
}
